import { createStore } from 'vuex'
import history from './modules/history'

const store = createStore({
  state() {
    return {
      user: null,
      isAuthenticated: false
    }
  },
  mutations: {
    SET_USER(state, user) {
      state.user = user
      state.isAuthenticated = true
    },
    LOGOUT(state) {
      state.user = null
      state.isAuthenticated = false
    }
  },
  actions: {
    login({ commit }, user) {
      // 这里应该是实际的登录逻辑
      commit('SET_USER', user)
    },
    logout({ commit }) {
      // 这里应该是实际的登出逻辑
      commit('LOGOUT')
    }
  },
  getters: {
    user: (state) => state.user,
    isAuthenticated: (state) => state.isAuthenticated
  },
  modules: {
    history
  }
})

export default store